<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "goods_img".
 *
 * @property int $id
 * @property string $goods_no 商品编号
 * @property string $src src
 * @property int $default 是否默认图片
 * @property int $addtime 添加时间
 */
class GoodsImg extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods_img';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['goods_no', 'src', 'addtime'], 'required'],
            [['goods_no', 'addtime'], 'integer'],
            [['src'], 'string', 'max' => 150],
            [['default'], 'string', 'max' => 1],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'goods_no' => '商品编号',
            'src' => 'src',
            'default' => '是否默认图片',
            'addtime' => '添加时间',
        ];
    }
    
    public static function getDefaultGoodsimgByGoodsno($goodsno){
        $sql = "select src from goods_img where goods_no=$goodsno";
        $command = \Yii::$app->db->createCommand($sql);
    	$model = $command->queryOne();
        return empty($model) ? "" : $model['src'];
    }
    
    public static function getImgsByGoodsno($goodsno){
        $sql = "select * from goods_img where goods_no = $goodsno";
        $command = \Yii::$app->db->createCommand($sql);
    	return $model = $command->queryAll();
    }
    
    public static function getDetailImgsByGoodsno($goodsno){
        $sql = "select src from goods_img where goods_no = $goodsno";
        $command = \Yii::$app->db->createCommand($sql);
    	return $model = $command->queryAll();
    }
    
}
